#!
$s1 = "abcdefghijklmnopq";
$s2 = "acbdfafsfsafsdfsfsfdsf";

sub cs
{

    my $l = shift;
    my $r = shift;

#     print "-------------------------------\n";
#     print "$l\n$r\n";
    return 0 if(length($l) == 0 or length($r) ==0);
   
    my ($l_head) = $l =~ /^(.)/;
    my ($r_head) = $r =~ /^(.)/;

#     print "-------------\n";
#     print "$l_head|$r_head\n";

    
    my $l_r = $l;
    my $r_r   = $r;

    $l_r =~ s/^.//;
    $r_r =~ s/^.//;

#     print "r = $r\n";
    if($l_head eq $r_head)
    {
        return 1 + cs($l_r, $r_r);
    }
    else
    {
#         print "computing: $l,$r_r\n";
#         print "r = $r\n";        
        my $cs1 = cs($l,$r_r);      
#         print "computing: $l_r,$r\n";
#         print "r = $r\n";
        my $cs2 = cs($l_r,$r);

        
#         print "---$cs1:$cs2\n";
        if($cs1>$cs2)
        {
            return $cs1;
        }
        else
        {
            return $cs2;
        }
    }
}

print cs($s1,$s2);
